import { ADD_COLLECT, REMOVE_COLLECT } from "../constant";

const initialState = {
  collectInfo: [], //存储用户点击收藏的商品Id
};

// eslint-disable-next-line import/no-anonymous-default-export
export default (state = initialState, { type, payload }) => {
  let newState = JSON.parse(JSON.stringify(state));
  // eslint-disable-next-line default-case
  switch (type) {
    case ADD_COLLECT:
      newState.collectInfo = {...state.collectInfo,...payload.collectInfo}
      break;
    case REMOVE_COLLECT:
      /* 判断redux 里面是否存在 */
     let index = newState.collectInfo.indexOf(payload.collectInfo)
      newState.collectInfo =  newState.collectInfo.splice(index,1)
      
      break;
  }
  return newState
};
